﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Insurance.ReadCard
{
    public partial class FrmReadType : DevExpress.XtraEditors.XtraForm
    {
        public string InputStr { set; get; } = "";

        /// <summary>
        /// 读卡类型 1 市民卡 2 虚拟卡 3 健康卡 4 刷脸
        /// </summary>
        public string ReadType { set; get; } = "1";

        public FrmReadType()
        {
            InitializeComponent();
        }

        private void FrmReadType_Load(object sender, EventArgs e)
        {
            tb_CardNo.Enabled = false;
            SetFormType(rb_市民卡);
            this.Focus();
            this.TopMost = false;
            this.BringToFront();
            this.TopMost = true;
            btn_Sure.Select();
            btn_Sure.Focus();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btn_Sure_Click(object sender, EventArgs e)
        {
            ReadCard();
        }

        private void SetFormType(RadioButton rb)
        {
            rb.ForeColor = rb.Checked ? Color.DodgerBlue : SystemColors.ControlText;
            if (rb.Checked)
            {
                ReadType = rb.Tag.ToString();
                if (rb.Tag.ToString() == "5")
                {
                    //刷脸
                    tb_CardNo.Enabled = true;
                    tb_CardNo.Text = string.Empty;
                    label2.Text = "手机号:";
                    tb_CardNo.Focus();
                }
                else if (rb.Tag.ToString() == "3")
                {
                    //刷码
                    tb_CardNo.Enabled = true;
                    tb_CardNo.Text = string.Empty;
                    label2.Text = "请刷码:";
                    tb_CardNo.Focus();
                }
                else
                {
                    tb_CardNo.Enabled = false;
                    label2.Text = "卡  号:";
                }
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void rb_市民卡_CheckedChanged(object sender, EventArgs e)
        {
            SetFormType(rb_市民卡);
        }

        private void rb_电子凭证_CheckedChanged(object sender, EventArgs e)
        {
            SetFormType(rb_电子凭证);
            if (rb_电子凭证.Checked)
            {
                ReadCard();
            }
        }

        private void rb_刷码_CheckedChanged(object sender, EventArgs e)
        {
            SetFormType(rb_刷码);
        }

        private void rb_健康卡_CheckedChanged(object sender, EventArgs e)
        {
            SetFormType(rb_健康卡);
            if (rb_健康卡.Checked)
            {
                ReadCard();
            }
        }

        private void ReadCard()
        {
            InputStr = tb_CardNo.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}